37 static void rcvChannel1(
const J2534::PASSTHRU_MSG * rxPassThruMsg,
unsigned long rxMsgNum);
38 static void rcvChannel2(
const J2534::PASSTHRU_MSG * rxPassThruMsg,
unsigned long rxMsgNum);
54 static pthread_mutex_t
screenMutex = PTHREAD_MUTEX_INITIALIZER;
69 J2534::PASSTHRU_MSG txPassThruMsg;
70 J2534::J2534_TxFlags txFlags;
73 memset(&txPassThruMsg, 0,
sizeof(J2534::PASSTHRU_MSG));
74 txFlags.bits.Can29BitId = 1;
75 txPassThruMsg.TxFlags = txFlags.value;
76 txPassThruMsg.ProtocolID = J2534::CAN;
78 txPassThruMsg.Data[0] =
static_cast<unsigned char>(
id >> 24);
79 txPassThruMsg.Data[1] =
static_cast<unsigned char>(
id >> 16);
80 txPassThruMsg.Data[2] =
static_cast<unsigned char>(
id >> 8);
81 txPassThruMsg.Data[3] =
static_cast<unsigned char>(
id >> 0);
84 txPassThruMsg.DataSize = 6;
88 cout <<
"CAN_GW periodic msg start ERROR! " << endl;
91 txPassThruMsg.Data[0] =
static_cast<unsigned char>(
id >> 24);
92 txPassThruMsg.Data[1] =
static_cast<unsigned char>(
id >> 16);
93 txPassThruMsg.Data[2] =
static_cast<unsigned char>(
id >> 8);
94 txPassThruMsg.Data[3] =
static_cast<unsigned char>(
id >> 0);
99 cout <<
"CAN_GW periodic msg start ERROR! " << endl;
105 txPassThruMsg.Data[0] =
static_cast<unsigned char>(
id >> 24);
106 txPassThruMsg.Data[1] =
static_cast<unsigned char>(
id >> 16);
107 txPassThruMsg.Data[2] =
static_cast<unsigned char>(
id >> 8);
108 txPassThruMsg.Data[3] =
static_cast<unsigned char>(
id >> 0);
110 txPassThruMsg.Data[5] =
'0';
111 txPassThruMsg.Data[6] =
'0';
112 txPassThruMsg.Data[7] =
'0';
113 txPassThruMsg.Data[8] =
'0';
114 txPassThruMsg.Data[9] =
'0';
115 txPassThruMsg.Data[10] = (i / 10) +
'0';
116 txPassThruMsg.Data[11] = (i % 10) +
'0';
117 txPassThruMsg.DataSize = 12;
120 cout <<
"CAN_GW send ERROR! " << endl;
126 cout <<
"CAN_GW send ERROR! " << endl;
130 static const unsigned int LOOP_DELAY = 5 * 1000;
137 cout <<
"CAN_GW uninit ERROR!" << endl;
142 cout <<
"CAN_GW init ERROR!" << endl;
143 cout <<
"Has application got superuser privileges?" << endl;
144 cout <<
"Is CAN Gateway connected?" << endl;
157 static void rcvChannel1(
const J2534::PASSTHRU_MSG * rxPassThruMsg,
unsigned long rxMsgNum)
161 for (
unsigned int i = 0; i < rxMsgNum; i++)
164 cout <<
"CHANNEL_1_cb | msg_src:ch" << rxPassThruMsg[i].Data[4];
165 cout <<
" | id:" <<
static_cast<unsigned int>(rxPassThruMsg[i].Data[0]);
166 cout <<
" " <<
static_cast<unsigned int>(rxPassThruMsg[i].Data[1]);
167 cout <<
" " <<
static_cast<unsigned int>(rxPassThruMsg[i].Data[2]);
168 cout <<
" " <<
static_cast<unsigned int>(rxPassThruMsg[i].Data[3]);
171 cout <<
" | periodic";
182 static void rcvChannel2(
const J2534::PASSTHRU_MSG * rxPassThruMsg,
unsigned long rxMsgNum)
186 for (
unsigned int i = 0; i < rxMsgNum; i++)
189 cout <<
"CHANNEL_2_cb | msg_src:ch" << rxPassThruMsg[i].Data[4];
190 cout <<
" | id:" <<
static_cast<unsigned int>(rxPassThruMsg[i].Data[0]);
191 cout <<
" " <<
static_cast<unsigned int>(rxPassThruMsg[i].Data[1]);
192 cout <<
" " <<
static_cast<unsigned int>(rxPassThruMsg[i].Data[2]);
193 cout <<
" " <<
static_cast<unsigned int>(rxPassThruMsg[i].Data[3]);
196 cout <<
" | periodic";
static pthread_mutex_t screenMutex
Mutex used by callback functions during accessing the screen.
Name of CAN Gateway's channel 2.
static const char PERIODIC_MSG_MARK
Marking for periodic messages.
ErrCode_e startPeriodic(Channel_e channel, J2534::PASSTHRU_MSG *txPassThruMsg, unsigned long interval)
Function starts CAN Gateway's periodic message.
static void rcvChannel1(const J2534::PASSTHRU_MSG *rxPassThruMsg, unsigned long rxMsgNum)
Callback function for receive on channel 1.
static const char CHANNEL_2_MARK
Marking for messages sent over channel 2.
Name of CAN Gateway's channel 1.
Header file for cangw.cpp.
ErrCode_e init(Baudrate_e baudChan1, Baudrate_e baudChan2, const RcvCb_t cbChan1, const RcvCb_t cbChan2)
Function initializes CAN Gateway device.
static const unsigned int MESSAGES_TO_SEND
Number of messages to send.
static void rcvChannel2(const J2534::PASSTHRU_MSG *rxPassThruMsg, unsigned long rxMsgNum)
Callback function for receive on channel 2.
int main()
The main function.
static const char CHANNEL_1_MARK
Marking for messages sent over channel 1.
static const unsigned int PERIODIC_MSG_INTERVAL
Period for periodic messages.
ErrCode_e send(Channel_e channel, J2534::PASSTHRU_MSG *txPassThruMsg)
Function sends PASSTHRU frame via given channel.
ErrCode_e uninit()
Function uninitializes CAN Gateway device.